<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php include_once '../functions.php';?>
        <?php
        // 一.接收Form表单的数据
        echo"categoryinsert<br>";
        //var_dump($_POST);
        //关联数据是键值对
        $name=$_POST['name'];
        echo "<br>$name<br>";
        //二.处理表单数据，操作数据表
        //1.连接数据库
        $link=  mysqli_connect("localhost", "root", "");//创建数据库连接，返回一数据库连接资源
        mysqli_select_db($link, "itcast");//选择要使用数据库
        mysqli_set_charset($link, "utf8");//设置连接的字符编码
        
        //2.操作数据表写SQL模板
        $sql="INSERT INTO shop_category(NAME,pid)VALUES('$name',0);";
        //mysqli_query(数据库的连接, sql语句) 如果做select 返回一个查询结果资源;如果是insert delete update 返回true或false；
        echo "<br>$sql<br>";
        $result=  mysqli_query($link, $sql);//
        var_dump($result);
        echo "<br>";
        //3.处理结果数据，并返回
        if($result){
//           echo "<script>alert('登录成功！');location.href='index.php'</script>";
            go_forward("分类添加成功", "categorylist.php");
        }else{
//            echo "<script>alert('用户名或密码错误！请继续努力！');location.href='login.php'</script>";
            go_forward("分类添加失败！", "categorylist.php");
        }
        ?>
    </body>
</html>
